import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-03-10
 * Time: 9:30
 */

@WebServlet("/hello")
// 父类中已经有了doGet. 此处希望用子类代替父类的
public class HolleServlet extends HttpServlet {
    @Override
    // 由Tomcat来自动调用
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 父类的doGet方法只是返回一个错误页面 需要注释掉
        //super.doGet(req, resp);
        System.out.println("hello world");

        // resp.getWriter()返回的是一个PrintWriter,这是一个打印输出流
        // resp.getWriter().write 只能打印文本输出格式(包括标签), 但不可以打印对象
        resp.getWriter().write("hello");


    }
}
